package com.amumu.netctoss.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.amumu.netctoss.dao.BillDao;
import com.amumu.netctoss.entity.Bill;
import com.amumu.netctoss.vo.BillItem;
import com.amumu.netctoss.vo.ServiceDetail;

public class BillAction extends BaseAction {
	@Resource
	private BillDao dao;
	
	private List<Bill> bills;
	private List<BillItem> items;
	private List<ServiceDetail> serviceDetails;
	private Bill bill;
	private BillItem billItem;
	private int billId;
	private int itemId;
	
	private String idcardNo;
	private String loginName;
	private String realName;
	private String yyyy;
	private String mm;
	
	public String list(){
		try {
			if(realName != null){
				realName = new String(realName.getBytes("iso8859-1"), "utf-8");
			}
			String month = "-1".equals(mm)? "%":mm;
			bills = dao.findList(page,PAGE_SIZE,idcardNo,loginName,realName,yyyy+month);
			pageCount = dao.getBillPages(PAGE_SIZE, idcardNo, loginName, realName, yyyy+month);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String item(){
		try {
			bill = dao.findBillById(billId);
			items = dao.findBillItems(page, PAGE_SIZE, billId);
			pageCount = dao.getItemPages(PAGE_SIZE, billId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String serviceDetail(){
		try {
			billItem = dao.findBillItemById(itemId);
			bill = dao.findBillById(billId);
			serviceDetails = dao.findServiceDetail(page, PAGE_SIZE, itemId);
			pageCount=dao.getDetailsPages(PAGE_SIZE, itemId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	
	
	//getter and setter
	public List<BillItem> getItems() {
		return items;
	}
	public BillItem getBillItem() {
		return billItem;
	}
	public Bill getBill() {
		return bill;
	}
	public List<ServiceDetail> getServiceDetails() {
		return serviceDetails;
	}
	public int getBillId() {
		return billId;
	}
	public List<Bill> getBills() {
		return bills;
	}

	public int getItemId() {
		return itemId;
	}
	public void setBillId(int billId) {
		this.billId = billId;
	}
	public void setItemId(int itemId) {
		this.itemId = itemId;
	}
	public String getIdcardNo() {
		return idcardNo;
	}

	public void setIdcardNo(String idcardNo) {
		this.idcardNo = idcardNo;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getYyyy() {
		return yyyy;
	}

	public void setYyyy(String yyyy) {
		this.yyyy = yyyy;
	}

	public String getMm() {
		return mm;
	}

	public void setMm(String mm) {
		this.mm = mm;
	}
//	http://localhost:8080/netctoss_v2/bill/list?idcardNo=330682196903190613&loginName=&realName=&yyyy=2013&mm=%&page=1
// http://localhost:8080/netctoss_v2/bill/list?idcardNo=330682196903190613&loginName=&realName=&yyyy=2013&mm=&page=1
}
